//
//  StatusRetweetedCell.swift
//  WeoboWithSteveLi
//
//  Created by SteveLi on 2017/10/17.
//  Copyright © 2017年 李军桦. All rights reserved.
//

import UIKit
///转发微博的cell
class StatusRetweetedCell: StatusCell {
    /// 微博视图模型
    ///如果继承父类的属性
    ///1.需要overide
    ///2.不需要 super
    ///3.先执行父类的 didSet,在执行子类的 didSet  -> 只关心 子类的相关设置就够了
   override var viewModel: StatusViewModel? {
        didSet {
            //转发微博的文字
            retweetedLabel.text = viewModel?.retweetedText
            
            pictureView.snp.updateConstraints { (make) in
                //根据配图数量,决定配图视图的顶部间距
                let offset = ((viewModel?.thumbnailUrls?.count ?? 0) > 0 ) ? StatusCellMargin : 0
                make.top.equalTo(retweetedLabel.snp.bottom).offset(offset)
            }
        }
    }
    
   
    //MARK: -懒加载控件
    lazy var backButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        return button
    }()
    ///转发标签
    lazy var retweetedLabel: UILabel = UILabel(title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博", fontSize: 14, color: UIColor.darkGray, screenInset: StatusCellMargin)
}

//MARK: -设置界面
extension StatusRetweetedCell {
    override func setupUI() {
        super.setupUI()
        //1.添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        //2.自动布局
        //1>背景按钮
        backButton.snp.makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp.left)
            make.right.equalTo(contentView.snp.right)
            make.bottom.equalTo(bottomView.snp.top)
        }
        //2.转发标签
        retweetedLabel.snp.makeConstraints { (make) in
            make.top.equalTo(backButton.snp.top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp.left).offset(StatusCellMargin)
        }
        //3> 配图视图
        pictureView.snp.makeConstraints { (make) in
            make.top.equalTo(retweetedLabel.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp.left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
    }
    
}
